package com.lifesting.workflow.diagram.ext.action;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.gef.Request;
import org.eclipse.gmf.runtime.diagram.ui.actions.DiagramAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IWorkbenchPage;

import com.lifesting.workflow.model.gd.GraphElement;
import com.lifesting.workflow.model.gd.diagram.part.WfgdDiagramEditorPlugin;

public class ViewModelAction extends DiagramAction {

	public ViewModelAction(IWorkbenchPage workbenchPage) {
		super(workbenchPage);
	}
	public static final String ID="com.lifesting.workflow.diagram.ext.view_model_action";
	@Override
	public void init() {
		super.init();
		setId(ID);
		setText("View Model");
		setDescription("View Model OK");
		setImageDescriptor(WfgdDiagramEditorPlugin.findImageDescriptor("icons/ext/obj16/virb_16.png"));
	}

	@Override
	protected Request createTargetRequest() {
		return null;
	}
	private GraphElement element;
	@Override
	protected boolean calculateEnabled() {
		element = null;
		if (getSelectedObjects().size() !=1 )return false;
		Object o = getSelectedObjects().get(0);
		if (o instanceof IAdaptable){
			return (element = (GraphElement) ((IAdaptable)o).getAdapter(GraphElement.class)) != null;
		}
		return false;
	}
	@Override
	protected boolean isSelectionListener() {
		return false;
	}
	@Override
	protected void doRun(IProgressMonitor progressMonitor) {
		System.out.println("vew model action : "+element.eContainer());
	}
	@Override
	public void refresh() {
		setEnabled(calculateEnabled());
	}
	
}
